package Pattern.AdapterPattern.program1;

abstract class Sound {//抽象声音类

    public abstract void phonate();
}

class ConcreteSound extends Sound {//具体声音类

    public void phonate() {
        System.out.println("声音播放！");
    }
}

abstract class Lamp {//抽象灯光类

    public abstract void twinkle();
}

class ConcreteLamp extends Lamp { //具体灯光类
    public void twinkle() {
        System.out.println("灯光闪烁！");
    }
}

/*(1) */ abstract class CarController {//汽车控制器

    public void move() {
        System.out.println("汽车移动！");
    }

    public abstract void sound();

    public abstract void light();
}

class CarAdapter/*(2)*/ extends CarController//汽车适配器
{
    private Sound sound;
    private Lamp lamp;

    public CarAdapter(Sound sound, Lamp lamp) {
        /*(3)*/
        this.sound = sound;
        /*(4)*/
        this.lamp = lamp;
    }

    public void sound() {
        /*(5)*/
        sound.phonate();//声音播放
    }

    public void light() {
        /*(6)*/
        lamp.twinkle();//灯光闪烁
    }
}

class Client {
    public static void main(String args[]) {
        Sound sound;
        Lamp lamp;
        CarController car;

        sound = new ConcreteSound();
        lamp = new ConcreteLamp();
        car = new CarAdapter(sound, lamp); //(7)
        car.move();
        car.sound();
        car.light();
    }
}

